package com.dfec.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.dfec.model.Msg;
import com.dfec.service.IUserService;
import com.dfec.service.imp.UserServiceImp;
import com.dfec.utils.Consists;
import com.dfec.utils.ResponseUtil;

/**
 * Servlet implementation class ActiveMailServlet
 */
@WebServlet(name = "actiive_mail", description = "激活邮箱", urlPatterns = { "/actiive_mail" })
public class ActiveMailServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ActiveMailServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String code=request.getParameter("code");

		IUserService userService=new UserServiceImp();
		Msg msg=new Msg();
		try {
			if(userService.activeUser(code)){
				msg.setCode(Consists.Error_Code_ActiveOK);
				msg.setMsg(Consists.Error_Msg_ActiveOK);
			}else{
				msg.setCode(Consists.Error_Code_Activefail);
				msg.setMsg(Consists.Error_Msg_Activefail);
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			msg.setCode(Consists.Error_Code_ServerError);
			msg.setMsg(Consists.Error_Msg_ServerError);
		}
		 List<Object> list =new ArrayList<>();
		 list.add(msg);
		ResponseUtil.sendScript(response, JSON.toJSONString(list));

	}
	




	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
